﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdventureApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var ctx = new AdventureWorks2008R2_DataEntities())
            {
                Console.WriteLine("Average big order {0:c}",
                    ctx.SalesOrderHeaders.Where(o=>o.TotalDue>2000).Average(o=>o.TotalDue));

                var sales = ctx.SalesOrderHeaders.
                    Where(o=>o.TotalDue > 2000);

                foreach (var order in sales)
                {
                    Console.WriteLine("Order: {0} - due: {1}, {2:c}",
                        order.SalesOrderNumber, order.DueDate, order.TotalDue);

                    foreach (SalesOrderDetail detail in order.SalesOrderDetails)
                    {
                        Console.WriteLine("\tQuantity {0}, tracking {1}",
                            detail.OrderQty, detail.CarrierTrackingNumber);
                    }
                }


                var q = from emp in ctx.People
                        where (emp.LastName == "Baker")
                        orderby emp.FirstName
                        select new
                        {
                            First = emp.FirstName,
                            Last = emp.LastName,
                            Title = emp.Title
                        };
                foreach (var data in q)
                {
                    Console.WriteLine("{0} {1}, {2}",
                        data.Title, data.Last, data.First);
                }
 
            }
        }
    }
}
